﻿@using Web_consultant.Database
@using Web_consultant.Database.Models
@model Web_consultant.Database.Models.User
@{
    ViewBag.Title = "Управление учетной записью";
}


<hgroup class="title">
    <h1>@ViewBag.Title.</h1>
</hgroup>

<p class="message-success">@ViewBag.StatusMessage</p>

<p>Вы вошли как <strong>@Session["Name"]</strong>.

@using (Html.BeginForm("Manage", "Account", FormMethod.Post, new {id = "Manage"}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <fieldset>
        <legend>Форма регистрации</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.Name)
                @Html.TextBoxFor(m => m.Name)
            </li>
            <li>
                @Html.LabelFor(m => m.LastName)
                @Html.TextBoxFor(m => m.LastName)
            </li>
            <li>
                @Html.LabelFor(m => m.Sex)
                @Html.RadioButtonFor(m => m.Sex, true) "Ж"
                @Html.RadioButtonFor(m => m.Sex, false) "М"
            </li>
            <li>
                @Html.LabelFor(m => m.Age)
                @Html.TextBoxFor(m => m.Age)
            </li>
            <li>
                @Html.LabelFor(m => m.Password)
                @Html.PasswordFor(m => m.Password)
            </li>
        </ol>
        <input type="submit" value="Внести изменения" />
        @if (Model.Role == 1)
        {
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>id</th>
                        <th>Имя</th>

                        <th>Фамилия</th>
                        <th>Пол</th>
                        <th>Роль</th>
                        <th>Проф. тест</th>
                        <th>Темперамент</th>
                        <th>EQ</th>
                    </tr>
                </thead>
                <tbody>  
                    @{
                        int f = 0;
                        var connector = new DbConnector();
                    }
                    @foreach (int a in Model.UsersId)
                    {
                        string sex;
                        string role;
                        //var connector = new Web_consultant.Database.DbConnector();
                        User user = connector.getUser(a);
                        string eq = connector.GetPassedTests(a, 4);
                        string temp = connector.GetPassedTests(a, 5);
                        string prof = connector.GetPassedTests(a, 7);
                        if (prof == "")
                        {
                            prof = connector.GetPassedTests(a, 8);
                        }
                        if (user.Sex == 1)
                        {
                            sex = "Ж";
                        }
                        else
                        {
                            sex = "М";
                        }
                        if (user.Role == 2)
                        {
                            role = "Инженер";
                        }
                        else
                        {
                            role = "Эксперт";
                        }


                        <tr>
                            <td>@f</td>
                            <td>@a</td>
                            <td>@user.Name</td>
                            <td>@user.LastName</td>
                            <td>@sex</td>
                            <td>@role</td>
                            <td>@prof</td>
                            <td>@temp</td>
                            <td>@eq</td>
                        </tr>

                        f++;
                    }
                </tbody> 
            </table>
            <button type="button" value="Добавить специалиста" onclick=" parent.location = '/Account/RegisterSpec' " >Добавить аккаунт для специалиста</button>
        }
        
        <br>
        
    </fieldset>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}